<template>
  <div class="riskInquiry">
    <div class="main" v-if="!isShowDetails">
      <div class="myFixed">
        <PageTitle
          :goBack="false"
          title="风险查询"
          :border="true"
          class="myFixed1"
        />
      </div>
      <div style="padding-top: 45px">
        <div class="myCardCss" style="width: 100%">
          <a-form :model="formData" :label-col="6" :wrapper-col="12">
            <a-form-item label="企业名称">
              <a-input
                style="width: 450px; border-radius: 4px"
                placeholder="请输入企业名称查询"
                v-model:value="formData.companyName"
              >
                <template #prefix>
                  <SearchOutlined/>
                </template>
              </a-input>
            </a-form-item>
            <a-form-item label="不良行为">
              <div style="display: flex; margin-left: 8px">
                <a-checkbox
                  @change="changeAny1"
                  :value="formData1.Any1"
                  :checked="checkedAny1"
                  name="type"
                ><span style="width: 28px; display: block">不限</span></a-checkbox
                >
                <div>
                  <a-checkbox-group
                    @change="changeOtherType1"
                    v-model:value="formData.type1"
                    :options="type1List"
                  />
                </div>
              </div>
            </a-form-item>
            <a-form-item label="司法信用">
              <div style="display: flex; margin-left: 8px">
                <a-checkbox
                  @change="changeAny2"
                  :value="formData1.Any2"
                  :checked="checkedAny2"
                  name="type"
                >不限
                </a-checkbox
                >
                <a-checkbox-group
                  @change="changeOtherType2"
                  v-model:value="formData.type2"
                  :options="type2List"
                />
              </div>
              <!-- <a-checkbox-group v-model:value="formData.type2">
                <a-checkbox
                  @change="changeOtherType"
                  :value="item"
                  name="type"
                  v-for="(item, index) in type2List"
                  :key="index"
                  >{{ item }}</a-checkbox
                >
              </a-checkbox-group> -->
            </a-form-item>
            <a-form-item label="行政处罚">
              <div style="display: flex; margin-left: 8px">
                <a-checkbox
                  @change="changeAny3"
                  :value="formData1.Any3"
                  :checked="checkedAny3"
                  name="type"
                ><span style="width: 28px; display: block">不限</span></a-checkbox
                >
                <div>
                  <a-checkbox-group
                    @change="changeOtherType3"
                    v-model:value="formData.type3"
                    :options="type3List"
                  />
                </div>
              </div>
            </a-form-item>
            <a-form-item v-if="false" label="企业名单">
              <a-checkbox @change="changeAny" :value="formData1.Any" :checked="checkedAny"
                          name="type"
              >不限
              </a-checkbox
              >
              <a-checkbox
                @change="changeWhite"
                :value="formData1.White"
                :checked="checkedWhite"
                name="type"
              >白名单
              </a-checkbox
              >
              <a-checkbox
                @change="changeFocus"
                :value="formData1.Focus"
                :checked="checkedFocus"
                name="type"
              >重点关注名单
              </a-checkbox
              >
              <a-checkbox
                @change="changeBlack"
                :value="formData1.Black"
                :checked="checkedBlack"
                name="type"
              >黑名单
              </a-checkbox
              >
            </a-form-item>
            <a-button
              type="primary"
              danger
              style="margin-left: 86px;margin-right: 12px; border-radius: 4px"
              @click="searchData()"
            >查询
            </a-button
            >
            <a-button @click="reset()" style="border-radius: 4px">重置</a-button>
          </a-form>
        </div>
        <div class="segmentation"></div>
        <div class="myCardCss" style="margin-bottom: 8px; width: 100%">
          <div class="list-top">
            <div class="list-count">
              <label>共找到</label>
              <label style="color: #c11a20"> {{ totalData }}</label>
              <label>条相关结果</label>
            </div>
          </div>
          <a-table
            class="detail-a-table__main"
            :dataSource="listData"
            :columns="columnsListData"
            :pagination="false"
            :bordered="true"
            :loading="loading"
            :scroll="{ x: 1000, y: 500 }"
          >
            <template #index="{ record, index }">
              {{ index + 1 + (pageNum - 1) * pageSize }}
            </template>
            <template #name="{ record }">
              <label
                style="color: #1473dc;cursor: pointer"
                v-html="getName(record.name)"
                @click="openDetails(record.companyId ? record.companyId : record.jskEid)"
              ></label
              >
              <!--              <div class="" v-if="record.markType">{{record.markType === 'WHITE' ? '白名单' : record.markType === 'BLACK' ? '黑名单' : '重点关注'}}</div>-->
              <div class="markState" :class="[
                        record.markType === 'WHITE'
                          ? 'tagWhite'
                          : record.markType === 'BLACK'
                          ? 'tagBlack'
                          : 'tagFocus'
                      ]" v-if="record.markType">{{
                  record.markType === 'WHITE'
                    ? '白名单'
                    : record.markType === 'BLACK'
                      ? '黑名单'
                      : '重点关注'
                }}
              </div>
            </template>
            <template #numXzcf="{ record }">
              <label style="color: #1473dc"
                     @click="openFxzs(record.name,record.companyId ? record.companyId : record.jskEid, record.behaviorTypeCount, 1, '行政处罚')"
              >{{ record.numXzcf }}</label>
            </template>
            <template #numCgbl="{ record }">
              <label style="color: #1473dc"
                     @click="openFxzs(record.name,record.companyId ? record.companyId : record.jskEid, record.behaviorTypeCount, 2, '采购不良')"
              >{{ record.numCgbl }}</label>
            </template>
            <template #numSfxy="{ record }">
              <label style="color: #1473dc"
                     @click="openFxzs(record.name,record.companyId ? record.companyId : record.jskEid, record.behaviorTypeCount, 3, '司法信用')"
              >{{ record.numSfxy }}</label>
            </template>
            <template #numFxzs="{ record }">
              <label style="color: #1473dc"
                     @click="openFxzs(record.name,record.companyId ? record.companyId : record.jskEid, record.behaviorTypeCount, 0, '')"
              >{{ record.fxzs }}</label>
            </template>
            <template #formerName="{ record }">
              <label style="color: #1473dc;cursor: pointer"
                     @click="open(record.companyId ? record.companyId : record.jskEid)"
              >查看</label>
            </template>
          </a-table>
          <!-- <a-pagination
                  size="small"
                  :total="pageForm.total"
                  :pageSize="pageForm.size"
                  :current="pageForm.limit"
                  :hideOnSinglePage="true"
                  @change="changePage"
                  style="margin-top: 30px; float: right"
                /> -->
          <!-- 法人关联企业弹窗 -->
          <a-modal
            v-model:visible="visible"
            :maskClosable="false"
            :width="1500"
            :centered="true"
            title="法人关联企业"
            style="padding: 80px"
            :footer="null"
            @cancel="closeModal"
          >
            <a-tabs style="padding: 16px 26px" v-model:activeKey="activeKey">
              <a-tab-pane key="1" tab="担任法人企业">
                <a-table
                  :dataSource="dataSource"
                  :columns="columns"
                  :pagination="false"
                  :bordered="true"
                  :scroll="{ x: 1000 }"
                  :loading="loading"
                >
                  <template #index="{ record, index }">
                    {{ index + 1 }}
                  </template>
                  <!-- <template #companyName="{ record }">
              <label style="color: #1473dc; cursor: pointer">{{ record.companyName }}</label>
            </template> -->
                </a-table>
                <a-pagination
                  size="small"
                  :total="pageForm.total"
                  :pageSize="pageForm.size"
                  :current="pageForm.limit"
                  :hideOnSinglePage="true"
                  :showSizeChanger="false"
                  @change="changePageOfM"
                  style="margin-top: 30px; float: right"
                />
              </a-tab-pane>
            </a-tabs>
          </a-modal>
          <!-- 风险总数弹窗 -->
          <a-modal
            v-model:visible="visibleFxzs"
            :maskClosable="false"
            :width="1600"
            :centered="true"
            :destroyOnClose="true"
            :title="modelTitle"
            style="padding: 80px"
            :footer="null"
          >
            <a-tabs style="padding: 16px 26px" v-model:activeKey="activeKeyFxzs"
                    @change="changeActive">
              <a-tab-pane key="1" tab="行政处罚" v-if="type === 0 || type === 1">
                <a-table
                  :dataSource="dataSourceFxzs"
                  :columns="columns1"
                  :pagination="false"
                  :bordered="true"
                  :scroll="{ x: 1000, y: 500 }"
                  :loading="loading"
                >
                  <template #index="{ record, index }">
                    {{ index + 1 + (pageFormFxzs.limit - 1) * pageFormFxzs.size }}
                  </template>
                </a-table>
                <a-pagination
                  size="small"
                  :total="pageFormFxzs.total"
                  :pageSize="pageFormFxzs.size"
                  :current="pageFormFxzs.limit"
                  :hideOnSinglePage="true"
                  :showSizeChanger="false"
                  @change="changePageByFxcx"
                  style="margin-top: 30px; float: right"
                />
              </a-tab-pane>
              <a-tab-pane key="2" tab="采购不良" v-if="type === 0 || type === 2">
                <a-tabs v-if="tab2List.length && visibleFxzs" v-model="activeKeyBy2" @change="changeActive2">
                  <a-tab-pane :key="item" :tab="item" v-for="item in tab2List"></a-tab-pane>
                </a-tabs>
                <a-table
                  :dataSource="dataSourceFxzs"
                  :columns="columns2"
                  :pagination="false"
                  :bordered="true"
                  :scroll="{ x: 1000, y: 500 }"
                  :loading="loading"
                >
                  <template #index="{ record, index }">
                    {{ index + 1 + (pageFormFxzs.limit - 1) * pageFormFxzs.size }}
                  </template>
                  <template #dishonest="{ record, index }">
                    {{ record.dishonest === '1' ? '失信' : '移除' }}
                  </template>
                </a-table>
                <a-pagination
                  size="small"
                  :total="pageFormFxzs.total"
                  :pageSize="pageFormFxzs.size"
                  :current="pageFormFxzs.limit"
                  :hideOnSinglePage="true"
                  :showSizeChanger="false"
                  @change="changePageByFxcx2"
                  style="margin-top: 30px; float: right"
                />
              </a-tab-pane>
              <a-tab-pane key="3" tab="司法信用" v-if="type === 0 || type === 3">
                <a-tabs v-if="tab2List.length" v-model="activeKeyBy2" @change="changeActive2">
                  <a-tab-pane :key="item" :tab="item" v-for="item in tab2List"></a-tab-pane>
                </a-tabs>
                <a-table
                  :dataSource="dataSourceFxzs"
                  :columns="columns3"
                  :pagination="false"
                  :bordered="true"
                  :scroll="{ x: 1000, y: 500 }"
                  :loading="loading"
                >
                  <template #index="{ record, index }">
                    {{ index + 1 + (pageFormFxzs.limit - 1) * pageFormFxzs.size }}
                  </template>
                  <template #dsr="{ record }">
                    <div>原告：{{ record.plaintiff }}</div>
                    <div>被告：{{ record.judge }}</div>
                  </template>
                  <template #relatedRelation="{ record }">
                    <div v-if="record.relatedRelation">
                      <div v-for="(item, index) in JSON.parse(record.relatedRelation)">
                        <label>{{item.role}}:{{item.name}}</label>
                      </div>
                    </div>
                  </template>
                  <template #relatedCompanies="{ record }">
                    <div v-if="record.relatedCompanies">
                      <div v-for="(item, index) in JSON.parse(record.relatedCompanies)">
                        <label>{{item.role}}:{{item.name}}</label>
                      </div>
                    </div>
                  </template>
                </a-table>
                <a-pagination
                  size="small"
                  :total="pageFormFxzs.total"
                  :pageSize="pageFormFxzs.size"
                  :current="pageFormFxzs.limit"
                  :hideOnSinglePage="true"
                  :showSizeChanger="false"
                  @change="changePageByFxcx2"
                  style="margin-top: 30px; float: right"
                />
              </a-tab-pane>
            </a-tabs>
          </a-modal>
        </div>
        <div class="otherPagination">
          <a-pagination
            size="small"
            :total="totalData"
            :pageSize="pageSize"
            :showSizeChanger="false"
            :current="pageNum"
            :hideOnSinglePage="true"
            @change="changePage"
            class="pag"
          />
        </div>
      </div>
    </div>
    <SupplierDetails v-if="isShowDetails" :company-id="companyId" @go-back="goBack"/>
  </div>
</template>
<script lang="ts" setup>
import {reactive, ref, watch} from 'vue';
import PageTitle from '/@/components/PageTitle/index.vue';
import {SearchOutlined} from '@ant-design/icons-vue';
import {
  getSearch,
  getCompanyListOfperson,
  getpenalize,
  getjmyq,
  getjdcgsx,
  getjdztcg,
  getzyqygysblxwjl,
  getzfcgwfsx,
  getexecutedPersons,
  getexecutions,
  getlimitHighConsumption,
  getcourtAnnouncement,
  getnotices,
  getlawsuits,
  getabnormals, getwfsx
} from '/@/api/riskInquiry';
import {changePost} from '/@/api/system/post';
import {getCompanyList} from '/@/api/supplierManage';
import SupplierDetails from "/@/components/SupplierDetails/index.vue";
import {message} from "ant-design-vue";

let formData = ref({
  companyName: '',
  type1: [],
  type2: [],
  type3: [],
});
let formData1 = ref({
  White: 'WHITE',
  Focus: 'FOCUS',
  Black: 'BLACK',
  Any1: '',
  Any2: '',
  Any3: '',
});
let loading = ref(false);
let listData = ref([]);
let totalData = ref(0);
let pageNum = ref(1);
let pageSize = ref(10);
let columnsListData = ref([
  {
    title: '序号',
    align: 'left',
    fixed: true,
    width: '80px',
    slots: {customRender: 'index'},
  },
  {
    title: '企业名称',
    dataIndex: 'name',
    key: 'name',
    align: 'left',
    width: '350px',
    fixed: true,
    slots: {customRender: 'name'},
  },
  // {
  //   title: '经营状态',
  //   dataIndex: 'businessStatus',
  //   key: 'businessStatus',
  //   align: 'left',
  //   width: '100px',
  // },
  {
    title: '行政处罚',
    dataIndex: 'numXzcf',
    key: 'numXzcf',
    align: 'left',
    width: '100px',
    slots: {customRender: 'numXzcf'},
  },
  {
    title: '采购不良',
    dataIndex: 'numCgbl',
    key: 'numCgbl',
    align: 'left',
    width: '100px',
    slots: {customRender: 'numCgbl'},
  },
  {
    title: '司法信用',
    dataIndex: 'numSfxy',
    key: 'numSfxy',
    align: 'left',
    width: '100px',
    slots: {customRender: 'numSfxy'},
  },
  {
    title: '风险总数',
    dataIndex: 'numPunish',
    key: 'numPunish',
    align: 'left',
    width: '100px',
    slots: {customRender: 'numFxzs'},
  },
  {
    title: '法人关联企业',
    dataIndex: 'formerName',
    key: 'formerName',
    align: 'left',
    width: '100px',
    slots: {customRender: 'formerName'},
  },
  {
    title: '法人代表',
    dataIndex: 'legalPerson',
    key: 'legalPerson',
    align: 'left',
    width: '100px',
  },
  {
    title: '统一社会信用代码',
    dataIndex: 'creditCode',
    key: 'creditCode',
    align: 'left',
    width: '300px',
  }
]);
let type1List = ref([
  '中央企业供应商不良行为记录',
  '政府采购严重违法失信行为记录',
  '军队采购失信名单',
  '军队采购暂停名单',
  '严重违法失信企业名单',
  '假冒中央企业名单',
]);
let type2List = ref([
  '被执行人',
  '失信被执行人',
  '限制高消费',
  '开庭公告',
  '法院公告',
  '裁判文书',
  // '经营异常',
]);
let type3List = ref([
  '围标串标',
  '虚假资料骗取中标',
  '以他人名义投标（违法资质挂靠）',
  '通过行贿等手段谋取中标或承揽工程',
  '超越资质范围或等级承揽工程',
  '以贿赂、欺骗等手段取得资质',
  '出现安全事故',
  '工程质量不达标',
  '违法转包分包',
  '转让、接受转入、冒用他人安全生产许可证（违法挂靠）',
  '未取得资质承揽工程',
  '无正当理由放弃中标',
]);
// let type4List = ref(['不限', '白名单', '重点关注名单', '黑名单']);

let checkedAny = ref(false);
let checkedAny1 = ref(false);
let checkedAny2 = ref(false);
let checkedAny3 = ref(false);
let checkedWhite = ref(false);
let checkedFocus = ref(false);
let checkedBlack = ref(false);
const changeAny1 = () => {
  checkedAny1.value = !checkedAny1.value;
  formData.value.type1 = [];
};
const changeOtherType1 = () => {
  console.log(formData.value.type2);
  checkedAny1.value = false;
};
const changeAny2 = () => {
  checkedAny2.value = !checkedAny2.value;
  formData.value.type2 = [];
};
const changeOtherType2 = () => {
  console.log(formData.value.type2);
  checkedAny2.value = false;
};
const changeAny3 = () => {
  checkedAny3.value = !checkedAny3.value;
  formData.value.type3 = [];
};
const changeOtherType3 = () => {
  console.log(formData.value.type2);
  checkedAny3.value = false;
};
const changeWhite = () => {
  checkedWhite.value = !checkedWhite.value;
  checkedAny.value = false;
  checkedFocus.value = false;
  checkedBlack.value = false;
  console.log('changeWhite');
  changeType4();
};
const changeFocus = () => {
  checkedFocus.value = !checkedFocus.value;
  checkedWhite.value = false;
  checkedAny.value = false;
  checkedBlack.value = false;
  changeType4();
};
const changeBlack = () => {
  checkedBlack.value = !checkedBlack.value;
  checkedWhite.value = false;
  checkedFocus.value = false;
  checkedAny.value = false;
  changeType4();
};

function reset() {
  formData.value = {
    companyName: '',
    type1: [],
    type3: [],
    type2: [],
  };
  checkedAny1.value = false;
  checkedAny2.value = false;
  checkedAny3.value = false;
  searchData();
}

async function searchData() {
  loading.value = true
  if (checkedBlack.value || checkedWhite.value || checkedFocus.value || checkedAny.value) {
    let needType = '';
    if (checkedBlack.value) {
      needType = formData1.value.Black;
    }
    if (checkedWhite.value) {
      needType = formData1.value.White;
    }
    if (checkedFocus.value) {
      needType = formData1.value.Focus;
    }
    if (checkedAny.value) {
      needType = formData1.value.Any;
    }
    let queryData1 = {
      type: needType,
      size: pageSize.value,
      limit: pageNum.value,
    };
    const res = await getCompanyList(queryData1);
    listData.value = res.list.map((item) => {
      let fxzs = 0
      let numCgbl = 0 // 不良行为总数
      let numSfxy = 0 // 司法风险总数
      let numXzcf = 0 // 行政处罚总数
      if (item.behaviorTypeCount) {
        for (let key in item.behaviorTypeCount) {
          // fxzs += item.behaviorTypeCount[key]
          if (type1List.value.includes(key)) {
            numCgbl += item.behaviorTypeCount[key]
          }
          if (type2List.value.includes(key)) {
            numSfxy += item.behaviorTypeCount[key]
          }
          if (type3List.value.includes(key)) {
            numXzcf += item.behaviorTypeCount[key]
          }
        }
        fxzs = numCgbl + numSfxy + numXzcf
      }
      return {
        ...item,
        fxzs,
        numSfxy,
        numCgbl,
        numXzcf,
        type: item.type == 'WHITE' ? '白名单' : item.type == 'BLACK' ? '黑名单' : '重点关注名单',
      };
    });
    totalData.value = res.total;
  } else {
    const type1 = formData.value.type1.filter((item) => item === '不限').length
      ? type1List.value.slice(1, type1List.value.length)
      : formData.value.type1;
    const type2 = formData.value.type2.filter((item) => item === '不限').length
      ? type2List.value.slice(1, type1List.value.length)
      : formData.value.type2;
    const type3 = formData.value.type3.filter((item) => item === '不限').length
      ? type3List.value.slice(1, type1List.value.length)
      : formData.value.type3;
    let typesList = type1.concat(type2).concat(type3);
    let queryData = {
      companyName: formData.value.companyName, // 公司名称
      types: typesList.toString(),
      size: pageSize.value,
      limit: pageNum.value,
    };
    if (queryData.types == '') {
      delete queryData.types;
    }
    let res = await getSearch(queryData);
    listData.value = res.list.map(item => {
      item.fxzs = 0
      item.numCgbl = 0 // 不良行为总数
      item.numSfxy = 0 // 司法风险总数
      item.numXzcf = 0 // 行政处罚总数
      if (item.behaviorTypeCount) {
        for (let key in item.behaviorTypeCount) {
          // item.fxzs += item.behaviorTypeCount[key]
          if (type1List.value.includes(key)) {
            item.numCgbl += item.behaviorTypeCount[key]
          }
          if (type2List.value.includes(key)) {
            item.numSfxy += item.behaviorTypeCount[key]
          }
          if (type3List.value.includes(key)) {
            item.numXzcf += item.behaviorTypeCount[key]
          }
        }
        item.fxzs = item.numCgbl + item.numSfxy + item.numXzcf
      }
      return item
    });
    console.log(listData.value)
    totalData.value = res.total;
  }
  loading.value = false
}

function changePage(val) {
  pageNum.value = val;
  searchData();
}

searchData();

// 企业名单checkboxChange
const changeType4 = () => {
  formData.value.type1 = [];
  formData.value.type2 = [];
  formData.value.type3 = [];
};
// 其余的checkboxChange
const changeOtherType = () => {
  checkedBlack.value = false;
  checkedWhite.value = false;
  checkedFocus.value = false;
  checkedAny.value = false;
};
// 风险总数弹窗
let dataSourceFxzs = ref([])
// 行政处罚
let columns1 = ref([
  {
    title: '序号',
    align: 'left',
    width: '50px',
    slots: {customRender: 'index'},
  },
  {
    title: '处罚日期',
    dataIndex: 'date',
    key: 'date',
    align: 'left',
    width: '120px',
  },
  {
    title: '处罚类别',
    dataIndex: 'dataType',
    key: 'dataType',
    align: 'left',
    width: '100px',
  },
  {
    title: '处罚原因',
    dataIndex: 'content',
    key: 'content',
    align: 'left',
    width: '300px',
  },
  {
    title: '处罚结果',
    dataIndex: 'results',
    key: 'results',
    align: 'left',
    width: '200px',
  },
  {
    title: '处罚金额（元）',
    dataIndex: 'punishMoney',
    key: 'punishMoney',
    align: 'left',
    width: '100px',
  },
  {
    title: '处罚机关',
    dataIndex: 'web',
    key: 'web',
    align: 'left',
    width: '200px',
  },
  {
    title: '决定文书号',
    dataIndex: 'docNo',
    key: 'docNo',
    align: 'left',
    width: '200px',
  },
]);
// 采购不良
let columns2 = ref([
  {
    title: '序号',
    align: 'left',
    width: '50px',
    slots: {customRender: 'index'},
  },
  {
    title: '处罚日期',
    dataIndex: 'relatedCompanyName',
    key: 'relatedCompanyName',
    align: 'left',
    width: '320px',
  },
  {
    title: '处罚类别',
    dataIndex: 'stockPercent',
    key: 'stockPercent',
    align: 'left',
    width: '100px',
  }
]);
// 司法信用
let columns3 = ref([]);
let activeKeyFxzs = ref('1');
let changeActive = () => {
  pageFormFxzs.value.limit = 1
  getFXZSData()
}
let activeKeyBy2 = ref('');
let changeActive2 = (val) => {
  activeKeyBy2.value = val
  pageFormFxzs.value.limit = 1
  getFXZSDataBy2()
}
let tab2List = ref([]) // 二级tab数组
let pageFormFxzs = ref({
  size: 10,
  limit: 1,
  total: 0,
});
let getFXZSData = async () => {
  loading.value = true
  if (activeKeyFxzs.value === '1') {
    let queryData = {
      pageIndex: pageFormFxzs.value.limit,
      pageSize: pageFormFxzs.value.size,
      cid: needMoId.value,
      isHistory: 0,
      dataTypes: [
        13,
        14,
        16,
        24,
        26,
        28,
        29,
        30,
        32,
        33,
        34,
        35
      ]
    }
    let res = await getpenalize(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
    loading.value = false
  } else if (activeKeyFxzs.value === '2') {
    tab2List.value = []
    type1List.value.map(item => {
      if (behaviorTypeCountList.value[item]) {
        console.log(11111, item)
        tab2List.value.push(item)
      }
    })
    if (!tab2List.value.length) {
      dataSourceFxzs.value = []
    } else {
      activeKeyBy2.value = tab2List.value[0]
      getFXZSDataBy2()
    }
    loading.value = false
  } else {
    tab2List.value = []
    type2List.value.map(item => {
      if (behaviorTypeCountList.value[item]) {
        tab2List.value.push(item)
      }
    })
    if (!tab2List.value.length) {
      dataSourceFxzs.value = []
    } else {
      activeKeyBy2.value = tab2List.value[0]
      getFXZSDataBy2()
    }
    loading.value = false
  }
}
let getFXZSDataBy2 = async () => {
  let queryData = {
    pageIndex: pageFormFxzs.value.limit,
    pageSize: pageFormFxzs.value.size,
    cid: needMoId.value,
  }
  // 司法信用
  if (activeKeyBy2.value === '被执行人') {
    columns3.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '立案日期',
        dataIndex: 'caseDate',
        key: 'caseDate',
        align: 'left',
        width: '80px',
      },
      {
        title: '执行标的（元）',
        dataIndex: 'amount',
        key: 'amount',
        align: 'left',
        width: '120px',
      },
      {
        title: '案号',
        dataIndex: 'caseNumber',
        key: 'caseNumber',
        align: 'left',
        width: '200px',
      },
      {
        title: '执法行院',
        dataIndex: 'court',
        key: 'court',
        align: 'left',
        width: '200px',
      }]
    let res = await getexecutedPersons(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '失信被执行人') {
    columns3.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '立案日期',
        dataIndex: 'date',
        key: 'date',
        align: 'left',
        width: '80px',
      },
      {
        title: '失信行为',
        dataIndex: 'finalDuty',
        key: 'finalDuty',
        align: 'left',
        width: '250px',
      },
      {
        title: '履行情况',
        dataIndex: 'executionStatus',
        key: 'executionStatus',
        align: 'left',
        width: '100px',
      },
      {
        title: '案号',
        dataIndex: 'caseNumber',
        key: 'caseNumber',
        align: 'left',
        width: '180px',
      },
      {
        title: '执法依据文号',
        dataIndex: 'docNumber',
        key: 'docNumber',
        align: 'left',
        width: '180px',
      },
      {
        title: '执行法院',
        dataIndex: 'court',
        key: 'court',
        align: 'left',
        width: '200px',
      }]
    let res = await getexecutions(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '限制高消费') {
    columns3.value = [
      {
        title: '序号',
        align: 'left',
        width: '50px',
        slots: {customRender: 'index'},
      }, {
        title: '立案日期',
        dataIndex: 'registerDate',
        key: 'registerDate',
        align: 'left',
        width: '80px',
      }, {
        title: '案由',
        dataIndex: 'content',
        key: 'content',
        align: 'left',
        width: '250px',
      },
      {
        title: '限制高消费人',
        dataIndex: 'name',
        key: 'name',
        align: 'left',
        width: '100px',
      },
      {
        title: '执行法院',
        dataIndex: 'court',
        key: 'court',
        align: 'left',
        width: '200px',
      }]
    let res = await getlimitHighConsumption(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '开庭公告') {
    columns3.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '开庭日期',
        dataIndex: 'hearingDate',
        key: 'hearingDate',
        align: 'left',
        width: '80px',
      },
      {
        title: '案由',
        dataIndex: 'causeAction',
        key: 'causeAction',
        align: 'left',
        width: '120px',
      },
      {
        title: '案号',
        dataIndex: 'caseNo',
        key: 'caseNo',
        align: 'left',
        width: '200px',
      },
      {
        title: '身份',
        dataIndex: 'pureRole',
        key: 'pureRole',
        align: 'left',
        width: '80px',
      },
      {
        title: '当事人',
        dataIndex: 'dsr',
        key: 'dsr',
        align: 'left',
        width: '200px',
        slots: {customRender: 'dsr'},
      },
      {
        title: '法庭',
        dataIndex: 'court',
        key: 'court',
        align: 'left',
        width: '200px',
      }]
    let res = await getcourtAnnouncement(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '法院公告') {
    columns3.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '公告时间',
        dataIndex: 'date',
        key: 'date',
        align: 'left',
        width: '80px',
      },
      {
        title: '案由',
        dataIndex: 'content',
        key: 'content',
        align: 'left',
        width: '200px',
      },
      {
        title: '公告类型',
        dataIndex: 'type',
        key: 'type',
        align: 'left',
        width: '100px',
      },
      {
        title: '当事人',
        dataIndex: 'relatedCompanies',
        key: 'relatedCompanies',
        align: 'left',
        width: '200px',
        slots: {customRender: 'relatedCompanies'},
      },
      {
        title: '法庭',
        dataIndex: 'court',
        key: 'court',
        align: 'left',
        width: '150px',
      }]
    let res = await getnotices(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '裁判文书') {
    columns3.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '公告时间',
        dataIndex: 'date',
        key: 'date',
        align: 'left',
        width: '80px',
      },
      {
        title: '案由',
        dataIndex: 'title',
        key: 'title',
        align: 'left',
        width: '200px',
      },
      {
        title: '公告类型',
        dataIndex: 'type',
        key: 'type',
        align: 'left',
        width: '100px',
      },
      {
        title: '当事人',
        dataIndex: 'relatedRelation',
        key: 'relatedRelation',
        align: 'left',
        width: '200px',
        slots: {customRender: 'relatedRelation'},
      },
      {
        title: '法庭',
        dataIndex: 'court',
        key: 'court',
        align: 'left',
        width: '150px',
      }]
    let res = await getlawsuits(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '经营异常') {
    columns3.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '列入日期',
        dataIndex: 'inDate',
        key: 'inDate',
        align: 'left',
        width: '80px',
      },
      {
        title: '列入经营异常名录原因',
        dataIndex: 'inReason',
        key: 'inReason',
        align: 'left',
        width: '200px'
      },
      {
        title: '列入经营异常做出决定机关',
        dataIndex: 'department',
        key: 'department',
        align: 'left',
        width: '100px',
      },
      {
        title: '移出日期',
        dataIndex: 'outDate',
        key: 'outDate',
        align: 'left',
        width: '80px',
      },
      {
        title: '移出经营异常名录原因',
        dataIndex: 'outReason',
        key: 'outReason',
        align: 'left',
        width: '200px'
      },{
        title: '移出经营异常做出决定机关',
        dataIndex: 'outDepartment',
        key: 'outDepartment',
        align: 'left',
        width: '100px',
      }]
    let res = await getabnormals(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }

  // 采购不良
  if (activeKeyBy2.value === '中央企业供应商不良行为记录') {
    columns2.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '被处理单位名称',
        dataIndex: 'company',
        key: 'company',
        align: 'left',
        width: '200px',
      },
      {
        title: '处理单位名称',
        dataIndex: 'clgs',
        key: 'clgs',
        align: 'left',
        width: '250px',
      },
      {
        title: '处理单位所属中央企业',
        dataIndex: 'source',
        key: 'source',
        align: 'left',
        width: '100px',
      },
      {
        title: '被处理原因',
        dataIndex: 'reason',
        key: 'reason',
        align: 'left',
        width: '200px',
      },
      {
        title: '处理结果',
        dataIndex: 'result',
        key: 'result',
        align: 'left',
        width: '100px',
      },
      {
        title: '处理开始日期',
        dataIndex: 'startDate',
        key: 'startDate',
        align: 'left',
        width: '100px',
      },
      {
        title: '处理结束日期',
        dataIndex: 'endDate',
        key: 'endDate',
        align: 'left',
        width: '100px',
      }]
    let res = await getzyqygysblxwjl(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '政府采购严重违法失信行为记录') {
    columns2.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '企业名称',
        dataIndex: 'company',
        key: 'company',
        align: 'left',
        width: '200px',
      },
      {
        title: '失信行为情形',
        dataIndex: 'sxxwqx',
        key: 'sxxwqx',
        align: 'left',
        width: '250px',
      },
      {
        title: '处罚结果',
        dataIndex: 'cfjg',
        key: 'cfjg',
        align: 'left',
        width: '250px',
      },
      {
        title: '处罚依据',
        dataIndex: 'cfyj',
        key: 'cfyj',
        align: 'left',
        width: '250px',
      },
      {
        title: '执法单位',
        dataIndex: 'zfdw',
        key: 'zfdw',
        align: 'left',
        width: '200px',
      },
      {
        title: '发布日期',
        dataIndex: 'fbrq',
        key: 'fbrq',
        align: 'left',
        width: '180px',
      }]
    let res = await getzfcgwfsx(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '军队采购失信名单') {
    columns2.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '企业名称',
        dataIndex: 'company',
        key: 'company',
        align: 'left',
        width: '200px',
      },
      {
        title: '失信行为情形',
        dataIndex: 'sxxwqx',
        key: 'sxxwqx',
        align: 'left',
        width: '250px',
      },
      {
        title: '处罚结果',
        dataIndex: 'cfjg',
        key: 'cfjg',
        align: 'left',
        width: '250px',
      },
      {
        title: '处罚机关',
        dataIndex: 'cfdw',
        key: 'cfdw',
        align: 'left',
        width: '150px',
      },
      {
        title: '处罚日期',
        dataIndex: 'cfrq',
        key: 'cfrq',
        align: 'left',
        width: '100px',
      },
    ]
    let res = await getjdcgsx(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '军队采购暂停名单') {
    columns2.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
     {
        title: '企业名称',
        dataIndex: 'company',
        key: 'company',
        align: 'left',
        width: '200px',
     },
     {
        title: '暂停事由',
        dataIndex: 'ztsy',
        key: 'ztsy',
        align: 'left',
        width: '250px',
      },
      {
        title: '开始日期',
        dataIndex: 'startDate',
        key: 'startDate',
        align: 'left',
        width: '100px',
      },
      // {
      //   title: '结束日期',
      //   dataIndex: 'endDate',
      //   key: 'endDate',
      //   align: 'left',
      //   width: '100px',
      // },
      {
        title: '状态',
        dataIndex: 'dishonest',
        key: 'dishonest',
        align: 'left',
        width: '100px',
        slots: {customRender: 'dishonest'},
      }]
    let res = await getjdztcg(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '严重违法失信企业名单') {
    columns2.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '列入日期',
        dataIndex: 'inDate',
        key: 'inDate',
        align: 'left',
        width: '100px',
      },
      {
        title: '做出决定机关',
        dataIndex: 'inDepartment',
        key: 'inDepartment',
        align: 'left',
        width: '200px'
      },
      {
        title: '列入严重违法失信名单（黑名单）原因',
        dataIndex: 'inReason',
        key: 'inReason',
        align: 'left',
        width: '300px'
      }]
    let res = await getwfsx(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
  if (activeKeyBy2.value === '假冒中央企业名单') {
    columns2.value = [{
      title: '序号',
      align: 'left',
      width: '50px',
      slots: {customRender: 'index'},
    },
      {
        title: '公示时间',
        dataIndex: 'publishDate',
        key: 'publishDate',
        align: 'left',
        width: '80px',
      },
      {
        title: '企业名称',
        dataIndex: 'company',
        key: 'company',
        align: 'left',
        width: '200px',
      },
      {
        title: '处理单位归属中央企业',
        dataIndex: 'belongOrg',
        key: 'belongOrg',
        align: 'left',
        width: '200px',
      },
      {
        title: '法人',
        dataIndex: 'legalPerson',
        key: 'legalPerson',
        align: 'left',
        width: '100px',
      },
      {
        title: '统一社会信用代码',
        dataIndex: 'creditCode',
        key: 'creditCode',
        align: 'left',
        width: '200px',
      }]
    let res = await getjmyq(queryData)
    dataSourceFxzs.value = res.list
    pageFormFxzs.value.total = res.total
  }
}
// 弹窗
let visible = ref(false);
let activeKey = ref('1');
let dataSource = ref([]);
let columns = ref([
  {
    title: '序号',
    align: 'left',
    width: '50px',
    slots: {customRender: 'index'},
  },
  {
    title: '企业名称',
    dataIndex: 'relatedCompanyName',
    key: 'relatedCompanyName',
    align: 'left',
    width: '320px',
  },
  {
    title: '持股比例',
    dataIndex: 'stockPercent',
    key: 'stockPercent',
    align: 'left',
    width: '100px',
  },
  {
    title: '注册资本',
    dataIndex: 'registeredCapital',
    key: 'registeredCapital',
    align: 'left',
    width: '100px',
  },
  {
    title: '地区',
    dataIndex: 'registeredAddress',
    key: 'registeredAddress',
    align: 'left',
    width: '100px',
  },
  {
    title: '经营状态',
    dataIndex: 'businessStatus',
    key: 'businessStatus',
    align: 'left',
    width: '200px',
  },
]);
let pageForm = ref({
  size: 10,
  limit: 1,
  total: 0,
});
let needMoId = ref('');
let visibleFxzs = ref(false)
let modelTitle = ref('法人关联企业')
let behaviorTypeCountList = ref([])
let type = ref(0)
const openFxzs = (name, id, behaviorTypeCount, key, modelName) => {
  let nameStr = name.replace(/<\/?.+?>/g,"").replace(/ /g,"");
  if (key) {
    activeKeyFxzs.value = key + ''
    modelTitle.value = nameStr + '--' + modelName
  } else {
    activeKeyFxzs.value = '1'
    modelTitle.value = nameStr
  }
  activeKeyBy2.value = ''
  tab2List.value = []
  behaviorTypeCountList.value = behaviorTypeCount
  pageFormFxzs.value.limit = 1
  visibleFxzs.value = true
  needMoId.value = id
  type.value = key
  getFXZSData()
}
const open = async (id) => {
  visible.value = true;
  getModelList(id);
  needMoId.value = id;
};
const getModelList = async (id) => {
  loading.value = true;
  let queryData = {
    cid: id,
    pageIndex: 1,
    pageSize: 10,
  };
  let res = await getCompanyListOfperson(queryData);
  dataSource.value = res.list;
  // pageForm.value.total = res.total;
  loading.value = false;
};
const changePageOfM = (val: number) => {
  getModelList(needMoId.value);
};
const changePageByFxcx = (val: number) => {
  pageFormFxzs.value.limit = val
  getFXZSData()
};
const changePageByFxcx2 = (val: number) => {
  pageFormFxzs.value.limit = val
  getFXZSDataBy2()
};

const closeModal = () => {
  visible.value = false;
  dataSource.value = [];
};
const getName = (name) => {
  if (formData.value.companyName.trim()) {
    return name.replaceAll(
      formData.value.companyName.trim(),
      `<span style="color: red;">${formData.value.companyName.trim()}</span>`,
    );
  }
  return name;
};
let isShowDetails = ref(false);
let companyId = ref('');

function openDetails(id: string) {
  if (id === '-') {
    return message.warning('未查到该公司详情');
  }
  companyId.value = id;
  isShowDetails.value = true;
}

function goBack() {
  isShowDetails.value = false;
}
</script>
<style lang="less" scoped>
.data-list {
  .data-item {
    border-bottom: 1px solid #dcdfe6;
    padding: 16px 0;

    .title {
      display: flex;

      .name {
        font-size: 20px;
        font-weight: 500;
        color: #1473dc;
      }

      .state {
        border: 1px solid #cdd0d6;
        padding: 0 8px;
        height: 24px;
        line-height: 24px;
        text-align: center;
        margin-left: 8px;
        margin-top: 5px;
        color: #606266;
      }
    }

    .tag {
      background: #f9e9e9;
      border: 1px solid #c11a20;
      width: fit-content;
      height: 24px;
      border-radius: 2px;
      line-height: 24px;
      text-align: center;
      color: #c11a20;
      padding: 0 8px;
      margin-top: 10px;
      margin-bottom: 12px;
    }

    .tagBlack {
      background: transparent;
      border: 1px solid #444548;
      width: fit-content;
      height: 24px;
      border-radius: 2px;
      line-height: 24px;
      text-align: center;
      color: #444548;
      padding: 0 8px;
      margin-top: 10px;
      margin-bottom: 12px;
    }

    .tagWhite {
      background: transparent;
      border: 1px solid #73cf8f;
      width: fit-content;
      height: 24px;
      border-radius: 2px;
      line-height: 24px;
      text-align: center;
      color: #73cf8f;
      padding: 0 8px;
      margin-top: 10px;
      margin-bottom: 12px;
    }

    .tagFocus {
      background: transparent;
      border: 1px solid #da7679;
      width: fit-content;
      height: 24px;
      border-radius: 2px;
      line-height: 24px;
      text-align: center;
      color: #da7679;
      padding: 0 8px;
      margin-top: 10px;
      margin-bottom: 12px;
    }

    .data-info {
      .info-row {
        display: flex;
        margin-bottom: 8px;

        .info-item {
          margin-right: 32px;
          font-size: 13px;

          .name {
            color: #909399;
          }

          .value {
            color: #303133;
          }

          .value1 {
            color: #1473dc;
          }
        }
      }

      .info-row:last-child {
        margin-bottom: 0px;
      }
    }
  }
}

.company {
  background: transparent;
  border: 1px solid #1473dc;
  height: 24px;
  border-radius: 2px;
  line-height: 24px;
  text-align: center;
  color: #1473dc;
  padding: 0 8px;
  margin-top: 6px;
  margin-bottom: 12px;
  margin-left: 12px;
  cursor: pointer;
}

.otherPagination {
  // float: right !important;
  margin-top: -10px;
  width: 100%;
  height: 32px;
  background-color: #fff !important;
  display: flex;
  flex-direction: row-reverse;
}

.segmentation {
  width: 100%;
  height: 10px;
  background: #f2f3f5;
}

.myFixed1 {
  //position: fixed;
  width: calc(100% - 7px);
  //box-sizing: border-box;
  //top: 0px;
  z-index: 10;
}

.myFixed {
  position: fixed;
  z-index: 10;
  width: calc(100% - 258px);
  background: #ffffff;
}

:deep(.myCardCss) {
  .ant-checkbox-wrapper {
    margin-bottom: 15px !important;
  }
}

.markState {
  width: fit-content;
  border: 1px solid #cdd0d6;
  padding: 0 8px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  margin-top: 5px;
  color: #606266;
}

.tag {
  background: #f9e9e9;
  border: 1px solid #c11a20;
  width: fit-content;
  height: 24px;
  border-radius: 2px;
  line-height: 24px;
  text-align: center;
  color: #c11a20;
  padding: 0 8px;
  margin-top: 10px;
  margin-bottom: 12px;
}

.tagBlack {
  background: transparent;
  border: 1px solid #444548;
  width: fit-content;
  height: 24px;
  border-radius: 2px;
  line-height: 24px;
  text-align: center;
  color: #444548;
  padding: 0 8px;
  margin-top: 10px;
  margin-bottom: 12px;
}

.tagWhite {
  background: transparent;
  border: 1px solid #73cf8f;
  width: fit-content;
  height: 24px;
  border-radius: 2px;
  line-height: 24px;
  text-align: center;
  color: #73cf8f;
  padding: 0 8px;
  margin-top: 10px;
  margin-bottom: 12px;
}

.tagFocus {
  background: transparent;
  border: 1px solid #da7679;
  width: fit-content;
  height: 24px;
  border-radius: 2px;
  line-height: 24px;
  text-align: center;
  color: #da7679;
  padding: 0 8px;
  margin-top: 10px;
  margin-bottom: 12px;
}
</style>
